package com.photoeditor.demo.ui.activity.setting;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.base.utils.AppUtils;
import com.photoeditor.R;
import com.photoeditor.demo.app.Global;
import com.photoeditor.demo.app.XActivity;
import com.photoeditor.demo.util.AndroidDevice;
import com.photoeditor.demo.util.FontUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by winn on 17/5/5.
 */

public class AboutActivity extends XActivity {
    @Bind(R.id.about_top)
    View mToolbarView;
    @Bind(R.id.filter_store_top_back)
    ImageView mToolbarBack;
    @Bind(R.id.filter_store_top_name)
    TextView mToolbarTitle;
    @Bind(R.id.about_version)
    TextView mAboutVersion;

    public static Intent newIntent(Context context) {
        Intent intent = new Intent(context, AboutActivity.class);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initContentView(savedInstanceState);
        initData(savedInstanceState);
    }

    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_about);
        ButterKnife.bind(this);
        mToolbarView.setBackgroundResource(R.drawable.store_top_panel_bg);
        mToolbarBack.setImageResource(R.drawable.icon_back);
        mToolbarTitle.setTextColor(getResources().getColor(R.color.title_color));
        FontUtil.setCustomFontBold(mToolbarTitle);
        FontUtil.setCustomFont(mAboutVersion);
        FontUtil.setCustomFont((TextView) findViewById(R.id.about_name));
        FontUtil.setCustomFont((TextView) findViewById(R.id.about_privacy));
        FontUtil.setCustomFont((TextView) findViewById(R.id.about_ad));
        FontUtil.setCustomFont((TextView) findViewById(R.id.tv_copyright));
    }

    public void initView(Bundle savedInstanceState) {
        Window window = getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE);
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }

    protected void initData(Bundle savedInstanceState) {
        mToolbarTitle.setText(getString(R.string.about));
        mAboutVersion.setText(AppUtils.getVersionNameByPkgName(this, getPackageName()));
    }


    @OnClick(R.id.filter_store_top_back)
    void onClickBack() {
        finish();
    }


    @OnClick(R.id.about_ad)
    void onClickAd() {
        AndroidDevice.startWebView(this, Global.AD_CHOICE);

    }

    @OnClick(R.id.about_privacy)
    void onClickPrivacy() {
        AndroidDevice.startWebView(this, Global.PRIVACY_URL);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @Override
    public void finish() {
        super.finish();
//        overridePendingTransition(0, R.anim.activity_close_exit);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }
}
